package com.example.mardan.views;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.example.mardan.adapter.YuanquAdapter;
import com.example.mardan.entity.YuanquChapter;
import com.example.mardan.viewmodel.YuanquViewModel;
import com.example.read.R;

import java.util.List;

public class YuanquActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private YuanquViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yuanqu);

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        viewModel = new ViewModelProvider(this).get(YuanquViewModel.class);
        viewModel.getYuanquList().observe(this, new Observer<List<YuanquChapter.ResultDTO>>() {
            @Override
            public void onChanged(List<YuanquChapter.ResultDTO> yuanquList) {
                YuanquAdapter adapter = new YuanquAdapter(yuanquList);
                recyclerView.setAdapter(adapter);
            }
        });
    }
}